package com.ly.config;


import com.ly.util.ExChangeNameUtil;
import com.ly.util.QueueNameUtil;
import com.ly.util.RoutingKeyUtil;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 李岩
 * @date 2022/1/11-8:59
 * @describe
 */
@Configuration
public class DirectConfig {
    //队列 起名：TestQueue
    @Bean
    public Queue DirectQueue() {
        //一般设置一下队列的持久化就好,其余两个就是默认false
        return new Queue(QueueNameUtil.DIRECT_QUEUE_NAME_EMAIL,true);
    }
    //Direct交换机 起名：TestDirectExchange
    @Bean
    DirectExchange DirectExchange() {
        return new DirectExchange(ExChangeNameUtil.DIRECT_EXCHANGE_USER,true,false);
    }
    //绑定  将队列和交换机绑定, 并设置用于匹配键：TestDirectRouting
    @Bean
    Binding bindingDirect() {
        return BindingBuilder.bind(DirectQueue()).to(DirectExchange())
                .with(RoutingKeyUtil.DIRECT_ROUTINGKEY_EMAIL);
    }
}

